﻿#region Copyright ©2008-2010, Technische Universitaet Muenchen
// ====================================================================================================
//
// Last Changed by       $Author: kalus $
// Last Changed Date     $LastChangedDate: 2009-03-18 16:42:33 +0100 (Wed, 18 Mar 2009) $
// Last Changed Revision $Rev: 36 $
//
// ====================================================================================================
#endregion

using System.Xml;
using Tum.CollabXT.VModellXT.Resources;

namespace Tum.CollabXT.VModellXT
{
    public class Topic : ProcessElement, ITopic
    {
        public Topic(XmlNode node)
        {
            Id = node.Attributes["id"].Value;
            Name = node.SelectSingleNode("Name").InnerText;

            XmlNode descNode = null;
            #region Get text block if availabe
            XmlNode descTextIdNode = node.SelectSingleNode("TextbausteinRef/@link");
            if (descTextIdNode != null)
            {
                descNode = node.OwnerDocument.SelectSingleNode(string.Format(Queries.MDL_GetTextBlock, descTextIdNode.Value));
                if (descNode != null)
                    ExtendedData["DescriptionRaw"] = descNode.InnerXml;
            }
            #endregion

            if (descNode == null)
            {
                descNode = node.SelectSingleNode("Beschreibung");
                if (descNode != null)
                    ExtendedData["DescriptionRaw"] = descNode.InnerXml;
            }

            object desc;
            if (ExtendedData.TryGetValue("DescriptionRaw", out desc))
                Description = Helper.GetTextFromHtmlString(desc as string);

            //Save number
            XmlNode nrNode = node.SelectSingleNode("Nummer");
            if (nrNode != null)
                Number = Helper.ParseNumber(nrNode.InnerText);
        }

        public int Number
        {
            get; set;
        }
    }
}
